function! api#easy#init() abort
    call s:align()
    call s:motion()
endfunction

function! s:align() abort
    if !exists("g:loaded_easy_align_plugin")
        try
            packadd vim-easy-align
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists("g:loaded_easy_align_plugin") && g:loaded_easy_align_plugin
        let g:async_keymap   = get(g:, "async_keymap", { "name" : "+async" })
        let g:async_keymap.a = [ "<Plug>(EasyAlign)" , "align" ]
        let g:space_keymap   = get(g:, "space_keymap", { "name" : "+space" })
        let g:space_keymap.a = g:async_keymap
        " Start interactive EasyAlign in visual mode (e.g. vip<Enter>)
        vmap ga <Plug>(EasyAlign)
        " Start interactive EasyAlign for a motion/text object (e.g. gaip)
        nmap ga <Plug>(EasyAlign)
    endif
endfunction

function! s:motion() abort
    if !exists('g:EasyMotion_loaded')
        try
            packadd vim-easymotion
        catch /.*/
            echoerr v:exception
        endtry
    endif
    if exists("g:EasyMotion_loaded") && g:EasyMotion_loaded
        map <Leader><Leader> <Plug>(easymotion-prefix)
        let g:space_keymap = get(g:, "space_keymap", { "name": "+space" })
        let g:easymotion_keymap = { "name": "+easymotion",
                    \ "b":     ["<Plug>(easymotion-b) ",     "b"],
                    \ "B":     ["<Plug>(easymotion-B) ",     "B"],
                    \ "d":     { "name": "+bidirection",
                    \            "f"   : ["<Plug>(easymotion-bd-f) ",  "f"],
                    \            "t"   : ["<Plug>(easymotion-bd-t) ",  "t"],
                    \            "w"   : ["<Plug>(easymotion-bd-w) ",  "w"],
                    \            "W"   : ["<Plug>(easymotion-bd-W) ",  "W"],
                    \            "e"   : ["<Plug>(easymotion-bd-e) ",  "e"],
                    \            "E"   : ["<Plug>(easymotion-bd-E) ",  "E"],
                    \            "j"   : ["<Plug>(easymotion-bd-jk)",  "jk"],
                    \            "n"   : ["<Plug>(easymotion-bd-n) ",  "n"],
                    \          },
                    \ "e":     ["<Plug>(easymotion-e) ",     "e"],
                    \ "E":     ["<Plug>(easymotion-E) ",     "E"],
                    \ "f":     ["<Plug>(easymotion-f) ",     "f"],
                    \ "F":     ["<Plug>(easymotion-F) ",     "F"],
                    \ "<c-e>": ["<Plug>(easymotion-ge)",     "ge"],
                    \ "<c-E>": ["<Plug>(easymotion-gE)",     "gE"],
                    \ "j":     ["<Plug>(easymotion-j) ",     "j"],
                    \ "k":     ["<Plug>(easymotion-k) ",     "k"],
                    \ "n":     ["<Plug>(easymotion-n) ",     "n"],
                    \ "N":     ["<Plug>(easymotion-N) ",     "N"],
                    \ "s":     ["<Plug>(easymotion-s) ",     "s"],
                    \ "t":     ["<Plug>(easymotion-t) ",     "t"],
                    \ "T":     ["<Plug>(easymotion-T) ",     "T"],
                    \ "w":     ["<Plug>(easymotion-w) ",     "w"],
                    \ "W":     ["<Plug>(easymotion-W) ",     "W"],
                    \ }
    endif
endfunction


"     More <Plug> Mapping Table         | (No assignment by default)
"     ----------------------------------|---------------------------------
"     <Plug>(easymotion-bd-f)           | See |<Plug>(easymotion-s)|
"     <Plug>(easymotion-bd-t)           | See |<Plug>(easymotion-bd-t)|
"     <Plug>(easymotion-bd-w)           | See |<Plug>(easymotion-bd-w)|
"     <Plug>(easymotion-bd-W)           | See |<Plug>(easymotion-bd-W)|
"     <Plug>(easymotion-bd-e)           | See |<Plug>(easymotion-bd-e)|
"     <Plug>(easymotion-bd-E)           | See |<Plug>(easymotion-bd-E)|
"     <Plug>(easymotion-bd-jk)          | See |<Plug>(easymotion-bd-jk)|
"     <Plug>(easymotion-bd-n)           | See |<Plug>(easymotion-bd-n)|
"     <Plug>(easymotion-jumptoanywhere) | See |<Plug>(easymotion-jumptoanywhere)|
"     <Plug>(easymotion-repeat)         | See |<Plug>(easymotion-repeat)|
"     <Plug>(easymotion-next)           | See |<Plug>(easymotion-next)|
"     <Plug>(easymotion-prev)           | See |<Plug>(easymotion-prev)|
"     <Plug>(easymotion-sol-j)          | See |<Plug>(easymotion-sol-j)|
"     <Plug>(easymotion-sol-k)          | See |<Plug>(easymotion-sol-k)|
"     <Plug>(easymotion-eol-j)          | See |<Plug>(easymotion-eol-j)|
"     <Plug>(easymotion-eol-k)          | See |<Plug>(easymotion-eol-k)|
"     <Plug>(easymotion-iskeyword-w)    | See |<Plug>(easymotion-iskeyword-w)|
"     <Plug>(easymotion-iskeyword-b)    | See |<Plug>(easymotion-iskeyword-b)|
"     <Plug>(easymotion-iskeyword-bd-w) | See |<Plug>(easymotion-iskeyword-bd-w)|
"     <Plug>(easymotion-iskeyword-e)    | See |<Plug>(easymotion-iskeyword-e)|
"     <Plug>(easymotion-iskeyword-ge)   | See |<Plug>(easymotion-iskeyword-ge)|
"     <Plug>(easymotion-iskeyword-bd-e) | See |<Plug>(easymotion-iskeyword-bd-e)|
"     <Plug>(easymotion-vim-n)          | See |<Plug>(easymotion-vim-n)|
"     <Plug>(easymotion-vim-N)          | See |<Plug>(easymotion-vim-N)|
"                                       |
"     Within Line Motion                | See |easymotion-within-line|
"     ----------------------------------|---------------------------------
"     <Plug>(easymotion-sl)             | See |<Plug>(easymotion-sl)|
"     <Plug>(easymotion-fl)             | See |<Plug>(easymotion-fl)|
"     <Plug>(easymotion-Fl)             | See |<Plug>(easymotion-Fl)|
"     <Plug>(easymotion-bd-fl)          | See |<Plug>(easymotion-sl)|
"     <Plug>(easymotion-tl)             | See |<Plug>(easymotion-tl)|
"     <Plug>(easymotion-Tl)             | See |<Plug>(easymotion-Tl)|
"     <Plug>(easymotion-bd-tl)          | See |<Plug>(easymotion-bd-tl)|
"     <Plug>(easymotion-wl)             | See |<Plug>(easymotion-wl)|
"     <Plug>(easymotion-bl)             | See |<Plug>(easymotion-bl)|
"     <Plug>(easymotion-bd-wl)          | See |<Plug>(easymotion-bd-wl)|
"     <Plug>(easymotion-el)             | See |<Plug>(easymotion-el)|
"     <Plug>(easymotion-gel)            | See |<Plug>(easymotion-gel)|
"     <Plug>(easymotion-bd-el)          | See |<Plug>(easymotion-bd-el)|
"     <Plug>(easymotion-lineforward)    | See |<Plug>(easymotion-lineforward)|
"     <Plug>(easymotion-linebackward)   | See |<Plug>(easymotion-linebackward)|
"     <Plug>(easymotion-lineanywhere)   | See |<Plug>(easymotion-lineanywhere)|
"                                       |
"     Multi Input Find Motion           | See |easymotion-multi-input|
"     ----------------------------------|---------------------------------
"     <Plug>(easymotion-s2)             | See |<Plug>(easymotion-s2)|
"     <Plug>(easymotion-f2)             | See |<Plug>(easymotion-f2)|
"     <Plug>(easymotion-F2)             | See |<Plug>(easymotion-F2)|
"     <Plug>(easymotion-bd-f2)          | See |<Plug>(easymotion-s2)|
"     <Plug>(easymotion-t2)             | See |<Plug>(easymotion-t2)|
"     <Plug>(easymotion-T2)             | See |<Plug>(easymotion-T2)|
"     <Plug>(easymotion-bd-t2)          | See |<Plug>(easymotion-bd-t2)|
"                                       |
"     <Plug>(easymotion-sl2)            | See |<Plug>(easymotion-sl2)|
"     <Plug>(easymotion-fl2)            | See |<Plug>(easymotion-fl2)|
"     <Plug>(easymotion-Fl2)            | See |<Plug>(easymotion-Fl2)|
"     <Plug>(easymotion-tl2)            | See |<Plug>(easymotion-tl2)|
"     <Plug>(easymotion-Tl2)            | See |<Plug>(easymotion-Tl2)|
"                                       |
"     <Plug>(easymotion-sn)             | See |<Plug>(easymotion-sn)|
"     <Plug>(easymotion-fn)             | See |<Plug>(easymotion-fn)|
"     <Plug>(easymotion-Fn)             | See |<Plug>(easymotion-Fn)|
"     <Plug>(easymotion-bd-fn)          | See |<Plug>(easymotion-sn)|
"     <Plug>(easymotion-tn)             | See |<Plug>(easymotion-tn)|
"     <Plug>(easymotion-Tn)             | See |<Plug>(easymotion-Tn)|
"     <Plug>(easymotion-bd-tn)          | See |<Plug>(easymotion-bd-tn)|
"                                       |
"     <Plug>(easymotion-sln)            | See |<Plug>(easymotion-sln)|
"     <Plug>(easymotion-fln)            | See |<Plug>(easymotion-fln)|
"     <Plug>(easymotion-Fln)            | See |<Plug>(easymotion-Fln)|
"     <Plug>(easymotion-bd-fln)         | See |<Plug>(easymotion-sln)|
"     <Plug>(easymotion-tln)            | See |<Plug>(easymotion-tln)|
"     <Plug>(easymotion-Tln)            | See |<Plug>(easymotion-Tln)|
"     <Plug>(easymotion-bd-tln)         | See |<Plug>(easymotion-bd-tln)|
" 
"     Over Window Motion                | (No assignment by default)
"     ----------------------------------|---------------------------------
"     <Plug>(easymotion-overwin-f)      | See |<Plug>(easymotion-overwin-f)|
"     <Plug>(easymotion-overwin-f2)     | See |<Plug>(easymotion-overwin-f2)|
"     <Plug>(easymotion-overwin-line)   | See |<Plug>(easymotion-overwin-line)|
"     <Plug>(easymotion-overwin-w)      | See |<Plug>(easymotion-overwin-w)|
